package com.frxuexi.park2304.user

import com.frxuexi.lib_base.http.ApiService
import com.frxuexi.lib_base.mvi.BaseViewModel
import com.frxuexi.lib_base.room.LoginDao
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

@HiltViewModel
class UserViewModel @Inject constructor(val apiService: ApiService,val loginDao: LoginDao):BaseViewModel<UserIntent>() {
    override fun handleIntent(it: UserIntent) {
        when(it){
            is UserIntent.login->httpRequest(apiService.login(it.uname,it.upass))
//            is UserIntent.login->roomRequest(flow { emit(loginDao.login(it.uname,it.upass)) })
            is UserIntent.register->roomRequest(flow { emit(loginDao.register(it.loginBean)) })
        }
    }
}